﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace SqlToolkit.Oracle.Schema
{
    public class SqlDbSequence : SqlBase
    {
        //SEQUENCE_NAME,MIN_VALUE,MAX_VALUE,INCREMENT_BY,CYCLE_FLAG,ORDER_FLAG,CACHE_SIZE,LAST_NUMBER

        private string _SEQUENCE_NAME = string.Empty;
        private string _MIN_VALUE = string.Empty;
        private string _MAX_VALUE = string.Empty;
        private string _INCREMENT_BY = string.Empty;
        private string _CYCLE_FLAG = string.Empty;
        private string _ORDER_FLAG = string.Empty;
        private string _CACHE_SIZE = string.Empty;
        private string _LAST_NUMBER = string.Empty;

        /// <summary>
        /// 
        /// </summary>
        public string SequenceName
        {
            get { return _SEQUENCE_NAME; }
            set { _SEQUENCE_NAME = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string MinValue
        {
            get { return _MIN_VALUE; }
            set { _MIN_VALUE = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string MaxValue
        {
            get { return _MAX_VALUE; }
            set { _MAX_VALUE = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string IncrementBy
        {
            get { return _INCREMENT_BY; }
            set { _INCREMENT_BY = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string CycleFlag
        {
            get { return _CYCLE_FLAG; }
            set { _CYCLE_FLAG = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string OrderFlag
        {
            get { return _ORDER_FLAG; }
            set { _ORDER_FLAG = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string CacheSize
        {
            get { return _CACHE_SIZE; }
            set { _CACHE_SIZE = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string LastNumber
        {
            get { return _LAST_NUMBER; }
            set { _LAST_NUMBER = value; }
        }


        public static SqlDbSequence Build(IDataReader r)
        {
            if (null == r) return null;

            SqlDbSequence ret = new SqlDbSequence();

            //SEQUENCE_NAME,MIN_VALUE,MAX_VALUE,INCREMENT_BY,CYCLE_FLAG,ORDER_FLAG,CACHE_SIZE,LAST_NUMBER
            if (null != r)
            {

                if (!r.IsDBNull(0))
                {
                    ret._SEQUENCE_NAME = Convert.ToString(r.GetValue(0));
                }


                if (!r.IsDBNull(1))
                {
                    ret._MIN_VALUE = Convert.ToString(r.GetValue(1));
                }


                if (!r.IsDBNull(2))
                {
                    ret._MAX_VALUE = Convert.ToString(r.GetValue(2));
                }


                if (!r.IsDBNull(3))
                {
                    ret._INCREMENT_BY = Convert.ToString(r.GetValue(3));
                }


                if (!r.IsDBNull(4))
                {
                    ret._CYCLE_FLAG = Convert.ToString(r.GetValue(4));
                }


                if (!r.IsDBNull(5))
                {
                    ret._ORDER_FLAG = Convert.ToString(r.GetValue(5));
                }


                if (!r.IsDBNull(6))
                {
                    ret._CACHE_SIZE = Convert.ToString(r.GetValue(6));
                }

                if (!r.IsDBNull(7))
                {
                    ret._LAST_NUMBER = Convert.ToString(r.GetValue(7));
                }

            }
            else
            {
                return null;
            }

            return ret;
        }

        public static SqlDbSequenceCollection BuildCollection(IDataReader r)
        {
            SqlDbSequenceCollection ret = new SqlDbSequenceCollection();

            while (r.Read())
            {
                ret.Add(Build(r));
            }

            if (ret.Count == 0) return null;

            return ret;
        }


    }
}
